package com.summer.framework.core.i18n;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.servlet.LocaleResolver;

import java.util.Locale;

/**
 * Description: 自定义国际化Resolver
 * @auther Ice Yang
 * Date 2025/7/2 14:07
 */
public class SummerLocalResolver implements LocaleResolver {

    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        String langParam = request.getParameter("lang");
        if (langParam != null && !langParam.isEmpty()) {
            return Locale.forLanguageTag(langParam);
        }
        // 2. 如果没有参数，检查 Accept-Language
        String acceptLanguage = request.getHeader("Accept-Language");
        if (acceptLanguage != null && !acceptLanguage.isEmpty()) {
            return request.getLocale();
        }
        // 3. 返回默认语言
        return Locale.ENGLISH;
    }

    @Override
    public void setLocale(HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Locale locale) {

    }
}
